package com.briup.day10;

import lombok.Getter;

public class Homework {
    public static void main(String[] args) {
        Shape rectangle = new Rectangle("Red", 2.0, 3.0);
        Shape circle = new Circle("Blue", 5);
        System.out.println(rectangle.getColor());
        System.out.println("Area:" + rectangle.area());
        System.out.println();
        System.out.println(circle.getColor());
        System.out.println("Area:" + circle.area());
    }
}

abstract class Shape {
    // 图形的颜色
    private String color;

    public Shape(String color) {
        this.color = color;
    }

    public String getColor() {
        return color;
    }

    protected abstract double area();
}

class Rectangle extends Shape {
    // 矩形的长
    private double length;
    // 矩形的宽
    private double width;

    public Rectangle(String color, double length, double width) {
        super(color);
        this.length = length;
        this.width = width;
    }

    @Override
    public double area() {
        return width * length;
    }
}

class Circle extends Shape {
    // 矩形的半径
    private double r;

    public Circle(String color, double r) {
        super(color);
        this.r = r;
    }

    @Override
    protected double area() {
        return Math.PI * r * r;
    }
}